package com.txooo.library.utils;

import android.text.TextUtils;

import java.text.DecimalFormat;

/**
 * Created by wwb on 2017/10/30.
 * 数字格式化
 */

public class NumPointFormat {

    public static String get2Str(double a) {
        DecimalFormat df = new DecimalFormat("0.00");
        return df.format(a).toString();
    }

    public static String get1Str(double a) {
        DecimalFormat df = new DecimalFormat("0.0");
        return df.format(a).toString();
    }


    public static String get2Str(String str) {
        if (!TextUtils.isEmpty(str)) {
            if (str.indexOf(".") > 0) {
                str = str.replaceAll("0+?$", "");//去掉多余的0
                str = str.replaceAll("[.]$", "");//如最后一位是.则去掉
            }
            DecimalFormat df = new DecimalFormat("0.00");
            return df.format(Double.valueOf(str)).toString();
        } else {
            return "0.00";
        }

    }
}
